COMMON_OBJ = obj_all/kernel.o obj_all/timer.o obj_all/db.o \
             obj_all/showmsg.o obj_all/utils.o obj_all/md52.o obj_all/sql.o    \
             obj_all/zlib.o obj_all/blowfish.o obj_all/taskmgr.o

COMMON_H   = mmo.h version.h  							\
             kernel.h timer.h db.h \
             showmsg.h utils.h md52.h blowfish.h 					\
             zlib.h sql.h lua/lua.h lua/lunar.h lua/lua.hpp lua/lualib.h lua/luaxlib.h		\
	     taskmgr.h	 


HAVE_MYSQL = @HAVE_MYSQL@

ifeq ($(HAVE_LUA),yes)
      ALL_DEPENDS = sql
else
      ALL_DEPENDS = needs_lua
endif

ifeq ($(HAVE_MYSQL),yes)
      ALL_DEPENDS = sql
else
      ALL_DEPENDS = needs_mysql
endif

@SET_MAKE@

#########################################################################################################

.PHONY: all sql clean help

all: $(ALL_DEPENDS)

sql: common

clean: 
	rm -rf *.o obj_all

help:
	@echo "possible targets are 'sql' 'all' 'clean' 'help'"
	@echo "'sql'   -   builds object files used in sql servers"
	@echo "'all'   -   builds all above targets"
	@echo "'clean' -   cleans builds and objects
	@echo "'help'  -   output this msg"

###########################################################################################################

needs_lua:
	@echo "Lua not found or disabled by the configure script"
	@exit 1

needs_mysql:
	@echo "MySQL not found or disabled by the configure script"
	@exit 1

common: obj_all $(COMMON_OBJ) $(COMMON_H)

obj_all:
	-mkdir obj_all
	-mkdir obj_all/lua

obj_all/%.o: %.cpp
	@CXX@  @CXXFLAGS@ @MYSQL_CFLAGS@ @CPPFLAGS@ -c $(OUTPUT_OPTION) $<

HAVESVN = $(shell which svnversion)

ifeq ($(findstring /,$(HAVESVN)), /)
svnversion.h:
	@printf "#define SVNVERSION " > svnversion.h
	@svnversion .. >> svnversion.h
	@printf "\n" >> svnversion.h
else
svnversion.h:
	@printf "\n" > svnversion.h
endif   
